package ngames.com.sushitv.temp.Presenter;

import android.os.Handler;
import android.os.Message;

import ngames.com.sushitv.AppApplication;
import ngames.com.sushitv.temp.Interface.FeaturedInterface;
import ngames.com.sushitv.temp.Interface.FeaturedTaskInterface;
import ngames.com.sushitv.temp.Module.FeaturedFractory;


/**
 * Created by edmond on 16-7-29.
 */
public class FeaturedPresenter implements FeaturedTaskInterface {
    private FeaturedFractory featuredFractory;
    private FeaturedInterface view;
    private AppApplication application;

    private Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what){
                case 0:
                    view.initingData(featuredFractory.getBanners(),featuredFractory.getFeaturedArray());
                    view.initedData();
                    break;
                case 2:
                    view.refreshedData(featuredFractory.getBanners(),featuredFractory.getFeaturedArray());
                    break;
            }
        }
    };

    public FeaturedPresenter(FeaturedFractory featuredFractory, FeaturedInterface view,AppApplication application){
        this.application = application;
        this.featuredFractory = featuredFractory;
        this.view = view;
    }

    @Override
    public void initData() {
        featuredFractory.initData(application,handler);
    }

    @Override
    public void refreshData() {
        view.refresinghData();
        featuredFractory.refreshData(handler);
    }
}
